import { createRouter, createWebHashHistory } from 'vue-router'
import { layoutRoutes } from './modules/layout'

const routesWhiteList = ['/login', '/404']

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      redirect: '/home',
      component: () => import('@/components/layout/index.vue'),
      children: layoutRoutes
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/index.vue')
    },
    {
      path: '/404',
      name: 'notFound',
      component: () => import('@/views/404/index.vue')
    },
    {
      path: '/:pathMatch(.*)',
      redirect: '/404'
    }
  ]
})

router.beforeEach((to, form, next) => {
  if (routesWhiteList.includes(to.path)) {
    next()
  } else {
    // 登录状态判断
    next()
  }
})

export default router
